package io.renren.modules.news.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.news.entity.PaomadengEntity;
import io.renren.modules.news.service.PaomadengService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;


/**
 * 
 * 
 * @author wxy
 * @email sharonwang_xy@163.com
 * @date 2018-10-16 01:00:38
 */
@RestController
@RequestMapping("news/paomadeng")
public class PaomadengController {
	@Autowired
	private PaomadengService paomadengService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("news:paomadeng:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<PaomadengEntity> paomadengList = paomadengService.queryList(query);
		int total = paomadengService.queryList(query.noLimit()).size();
		
		PageUtils pageUtil = new PageUtils(paomadengList, total, query.getLimit(), query.getCurrPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("news:paomadeng:info")
	public R info(@PathVariable("id") Integer id){
		PaomadengEntity paomadeng = paomadengService.queryObject(id);
		
		return R.ok().put("paomadeng", paomadeng);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("news:paomadeng:save")
	public R save(@RequestBody PaomadengEntity paomadeng){
		paomadengService.save(paomadeng);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("news:paomadeng:update")
	public R update(@RequestBody PaomadengEntity paomadeng){
		paomadengService.update(paomadeng);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("news:paomadeng:delete")
	public R delete(@RequestBody Integer[] ids){
		paomadengService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
